<template>
  <div>
    <div>
      <el-row style="background: white">
        <el-col :span="24">
          <div class="tbUpDiv">
            <img src="src/public/imgs/6ZGSYR_%5DVV%5B03$E1XCH)GFI.png" class="tbImg">
            <span class="tbUpPost">录用意向</span>
         </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <div class="tbScenDiv">
            <div style="display: flex;
                        margin-top: 10px;">
              <div style=""><span style="font-size: 14px">应聘岗位：</span><br><el-input v-model="souForm.jobdemandName" @keyup.enter="JobMohu()"/></div>
              <div style="margin-left: 30px"><span style="font-size: 14px">候选人姓名：</span><br><el-input v-model="souForm.interviName" @keyup.enter="JobMohu()"/></div>
              <div style="margin-left: 30px"><span style="font-size: 14px">手机号码：</span><br><el-input v-model="souForm.personnelPhone" @keyup.enter="JobMohu()"/>
              </div>
              <div style="margin-top: 20px;margin-left: 30px">
                <el-button @click="chongzhi()">重置</el-button>
              </div>
            </div>
          </div>
        </el-col>
          </el-row>
    </div>
    <el-row>
      <el-col>
        <el-table :data="d.tableData" @row-click="dianjixq"  style="width: 100%; margin-top: 20px">
          <el-table-column align='center' prop="interviName" label="姓名" width="180" />
          <el-table-column align='center' prop="personnelPhone" label="手机号码" width="180" />
          <el-table-column align='center' prop="jobdemandName" label="岗位" width="180" />
          <el-table-column align='center' prop="inductionSalary" label="薪资" width="180" />
          <el-table-column align='center' prop="inductionDate" label="通知时间" width="180">
            <template #default="s">
              <span>{{s.row.inductionDate.slice(0,10)}}</span>
            </template>
          </el-table-column>
          <el-table-column align='center' prop="inductionSteta" label="offer状态">
            <template #default="s">
              <div style="background:rgb(234,242,251);color:#446af3;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="s.row.inductionSteta==0">待确定</div>
              <div style="background:rgb(252,240,241);color:#D93e34;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="s.row.inductionSteta==2">已拒绝</div>
              <div style="background:rgb(217,246,229);color:#479d5c;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="s.row.inductionSteta==1">已确定</div>
            </template>
          </el-table-column>
          <el-table-column align='center'  label="操作" >
            <template #default="s">
             <el-button v-if="s.row.inductionSteta==0" @click.stop="offQd(s.row.inductionId,s.row.jobdemandName,s.row.interviName,s.row.personnelPhone)">已确定</el-button>
              <el-button v-if="s.row.inductionSteta==0" @click.stop="offJj(s.row.inductionId,s.row.interviName)">已拒绝</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-row justify="center">
      <el-col>
        <el-pagination
            v-model:currentPage="d.pageNo"
            v-model:page-size="d.pageSize"
            :page-sizes="[5,10, 20, 30, 40]"
            small="small"
            layout="total, sizes, prev, pager, next, jumper"
            :total="d.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
      </el-col>
    </el-row>
    <el-dialog v-model="d.formJobPost2" title="offer操作记录" style="text-align: center">
      <el-table :data="d.tableData2" style="width: 100%">
        <el-table-column align='center'  prop="inductionName" label="姓名" width="180" />
        <el-table-column align='center'  prop="inductionSteta" label="offer原状态" width="180">
          <template #default="s">
            <div style="background:rgb(234,242,251);color:#446af3;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="s.row.inductionSteta==0">未确定</div>
            <div style="background:rgb(252,240,241);color:#D93e34;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="s.row.inductionSteta==2">已拒绝</div>
            <div style="background:rgb(217,246,229);color:#479d5c;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="s.row.inductionSteta==1">已确定</div>
          </template>
        </el-table-column>
        <el-table-column align='center' prop="inductionNsteta" label="offer现状态">
          <template #default="ss">
            <div style="background:rgb(234,242,251);color:#446af3;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="ss.row.inductionNsteta==0">未确定</div>
            <div style="background:rgb(252,240,241);color:#D93e34;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="ss.row.inductionNsteta==2">已拒绝</div>
            <div style="background:rgb(217,246,229);color:#479d5c;height:80%;width:60%;margin:0 20% 0;font-size: 12px" v-if="ss.row.inductionNsteta==1">已确定</div>
          </template>
        </el-table-column>
        <el-table-column align='center' prop="inducrecordingDate" label="操作时间" />
      </el-table>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import {reactive, ref,onBeforeMount} from "vue";
import {useRouter} from "vue-router";
import router from "../../router";
import axios from "axios";
import moment from "moment";
import {ElMessage} from "element-plus";
const d = reactive({
  //总记录
  total:0,
  //页码
  pageNo:1,
  //页大小
  pageSize:5,
  //数据
  tableData:[],
  //记录数据
  tableData2:[],
  formJobPost2:false,
  //岗位需求人数
    grs:0,
  //入职岗位人数
    rrs:0,
  //岗位id
    jobdemandId:'',
  //性别id
    resumeId:'',
    resumesex:'',
  //部门id
  deptId:'',
});
const ALltableData=ref([])
const getTabelData=()=>{//分页，这里没必要管一样就行
  let data =JSON.parse(JSON.stringify(ALltableData.value));//把数据转为JSON格式
  let shu = data.splice(
      (d.pageNo - 1) * d.pageSize,
      d.pageSize
  )
  d.tableData = shu ;
}

const handleSizeChange = (val: number) => {//分页，这里没必要管一样就行
  d.pageSize = val ;
  d.pageNo = 1;
  getTabelData();
}

const handleCurrentChange = (val: number) => {//分页，这里没必要管一样就行
  d.pageNo = val;
  getTabelData();
}
const getDate =()=>{
  axios.post("http://localhost:9884/inductions/selectInduction").then((res)=>{
    var data=res.data.data
    ALltableData.value = data;//放入表格
    d.total = res.data.data.length;//获得它的长度
    getTabelData();//调用方法
  })
}

const souForm=reactive({
  interviName:'',
  jobdemandName:'',
  personnelPhone:'',
})
//选中元素事件,搜索
const JobMohu=()=>{
  axios.post("http://localhost:9884/inductions/selsectInducMoHu",souForm).then((res)=>{
    var data=res.data.data
    ALltableData.value = data;//放入表格
    d.total = res.data.data.length;//获得它的长度
    getTabelData();//调用方法
  })
  console.log(souForm)
}
//重置搜索
const chongzhi = () => {
  souForm.interviName='',
      souForm.jobdemandName='',
      souForm.personnelPhone='',
      getDate()
}
//定义记录表数据
let str = moment(new Date()).format("YYYY-MM-DD hh:mm:ss")
const jiluForm=reactive({
  inductionName:'',
  inductionSteta:0,
  inductionNsteta:0,
  inducrecordingDate:str,
})
const fun11 =async  function(jobdemandName,personnelPhone,interviName){
 await axios.post("http://localhost:1688/jobre/selectJob/"+jobdemandName)
      .then((res)=>{
        console.log(res.data.data[0])
        d.jobdemandId=res.data.data[0].jobrecordId;
        datfrom.valueDepartment=res.data.data[0].deptId
        datfrom.valuePoition=res.data.data[0].jobrecordId;
        datfrom.name=interviName
        d.deptId=res.data.data[0].deptId
        console.log(d.jobdemandId)
        axios.post("http://localhost:1688/resume/selectPhone/"+personnelPhone)
            .then((res)=>{
              if(res.data.data[0].resumeSex=='男'){
                datfrom.valueSex=1
              }else{
                datfrom.valueSex=2
              }
            })
        console.log(datfrom)
        let json = JSON.stringify(datfrom);
        var forms = new FormData();
        forms.append("json", json);
        const url = "http://localhost:1688/record/saveRecord";
        axios.post(url,forms).then((data)=>{

        });

      })
}
//用户已确定
const offQd = (inductionId,jobdemandName,interviName,personnelPhone) => {
   axios.post("http://localhost:1688/inductions/updateOfferSteta/"+1+"/"+inductionId)
       .then((res)=>{
         //根据岗位职称查询到岗位需求人数
         axios.post("http://localhost:1688/jobdemand/selectJobDmanName/"+jobdemandName).then((res)=>{
          console.log(res.data.data[0].jobdemandNumber)
           d.grs=res.data.data[0].jobdemandNumber;
         })
         //查询入职岗位人数
         axios.post("http://localhost:9884/inductions/selectJobName/"+jobdemandName).then((res)=>{
           console.log(res.data.data.length)
           d.rrs=res.data.data.length;
         })
         if(d.rrs>d.grs || d.rrs==d.grs){
           axios.post("http://localhost:1688/jobdemand/updateJjobdemandName/"+2+"/"+jobdemandName)
               .then((res)=>{
                 console.log("成功")
                 //岗位实际人数增加
                 axios.post("http://localhost:1688/jobre/updatesnumber/"+1+"/"+jobdemandName)
                     .then((res)=>{
                      console.log("人数增加成功")

                    })
              })
        }else{
          console.log("人数还不够")
        }
        //新增入职记录
        jiluForm.inductionName=interviName
        jiluForm.inductionSteta=0
        jiluForm.inductionNsteta=1
        console.log(jiluForm)
        axios.post("http://localhost:9884/indrecoding/addindrecoding",jiluForm)
            .then((res)=>{
              console.log('成功')
            })
        getDate()
       fun11(jobdemandName,personnelPhone,interviName)
       })
}
const datfrom = reactive({
  valueDepartment:"",
  valuePoition:"",
  valueSex:1,
  name:""
})
//用户已拒绝
const offJj = (inductionId,interviName) => {
  axios.post("http://localhost:1688/inductions/updateOfferSteta/"+2+"/"+inductionId)
      .then((res)=>{
        jiluForm.inductionName=interviName
        jiluForm.inductionSteta=0
        jiluForm.inductionNsteta=2
        console.log(jiluForm)
        axios.post("http://localhost:9884/indrecoding/addindrecoding",jiluForm)
            .then((res)=>{
              console.log('成功')
            })
        getDate()
        dangan()
      })

}
//查看详情
const dianjixq = (row) => {
  console.log(row)
  d.formJobPost2 = true;
  axios.post("http://localhost:1688/indrecoding/selectJobByName/"+row.interviName).then((res)=>{
    d.tableData2=res.data.data

  })
}
//查询性别 部门 岗位id
const dangan = () => {

}
onBeforeMount(function () {
  getDate()
})
</script>
<style scoped>
.tbUpDiv{
  width: 100%;
  border-top: 1px solid gainsboro;
  border-bottom: 1px solid gainsboro;
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.tbImg{
  margin-left: 20px;
}
.tbUpPost{
  margin-left: 10px;
  display: flex;
  align-items: center;
}
.tbScenDiv{
  border-bottom: 1px solid gainsboro;
  position: relative;
}

</style>